package com.ma.controller;




import com.ma.common.lang.Result;
import com.ma.entity.*;
import com.ma.mapper.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class TestController {

    @Autowired
    private SysRoleMapper sysRoleMapper;

    @Autowired
    private BCryptPasswordEncoder bCryptPasswordEncoder;
    /*
        测试密码加密
     */
    @GetMapping("/pass")
    public Result pass(){
        //加密后的密码
        String encode = bCryptPasswordEncoder.encode("123456");
        boolean matches = bCryptPasswordEncoder.matches("123456", encode);
        System.out.println("加密匹配结果"+matches);
        return Result.succ(encode);
    }


    //超级管理员
    @PreAuthorize("hasRole('admin')")
    @GetMapping("/Test")
    public List<SysRole> selectAll(){
        List<SysRole> sysRoles = sysRoleMapper.selectAll();
        return sysRoles;
    }

    //普通用户  超级管理员
    @Autowired
    private SysRoleMenuMapper sysRoleMenuMapper;
    @PreAuthorize("hasAuthority('sys:menu:list')")
    @GetMapping("/Test1")
    public List<SysRoleMenu> selectAllsysRoleMenus(){
        List<SysRoleMenu> sysRoleMenus = sysRoleMenuMapper.selectAll();
        return sysRoleMenus;
    }



    @Autowired
    private SysUserMapper sysUserMapper;

    @GetMapping("/Test2")
    public Result selectAllsysUsers(){
        List<SysUser> sysUsers = sysUserMapper.selectAll();
        return Result.succ(sysUsers);
    }
    @Autowired
    private SysUserRoleMapper sysUserRoleMapper;

    @GetMapping("/Test3")
    public List<SysUserRole> selectAllsysRoles(){
        List<SysUserRole> sysRoles = sysUserRoleMapper.selectAll();
        return sysRoles;
    }

    @Autowired
    private SysMenuMapper sysMenuMapper;

    @GetMapping("/Test4")
    public List<SysMenu> selectAllsyssysMenuMapper(){
        List<SysMenu> sysMenuList = sysMenuMapper.selectAll();
        return sysMenuList;
    }
}
